package com.demo.service.impl;

import com.demo.dao.ShoppingCartDao;
import com.demo.model.OrderExpand;
import com.demo.model.ShoppingCart;
import com.demo.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ShoppingCartServiceImpl implements ShoppingCartService {
    @Autowired
    private ShoppingCartDao shoppingCartDao;

    @Override
    public int save(ShoppingCart shoppingCart) {
        return shoppingCartDao.insert(shoppingCart);
    }

    @Override
    public ShoppingCart getShoppingCartById(Integer id) {
        return shoppingCartDao.selectOne(id);
    }

    @Override
    public Integer updateShoppingCart(ShoppingCart shoppingCart) {
        if (shoppingCart.getId() != null && shoppingCart.getId() > 0) {
            return shoppingCartDao.update(shoppingCart);
        }
        return shoppingCartDao.insert(shoppingCart);
    }

    @Override
    public Integer deleteShoppingCart(int id) {
        return shoppingCartDao.delete(id);
    }

    @Override
    public List<ShoppingCart> getShoppingCart(Integer productId) {
        return shoppingCartDao.select(productId);
    }

    @Override
    public List<ShoppingCart> getShoppingCartByUserId(Integer userId) {
        return shoppingCartDao.selectOneByUserId(userId);
    }

}
